package com.zzyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDTO;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    //添加
    @Override
    public void addNursingLevel(NursingLevelDTO nursingLevelDto) {
        //转换
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.addNursingLevel(nursingLevel);
    }

    //修改护理等级信息
    @Override
    public void updateNursingLevel(NursingLevelDTO nursingLevelDto) {
        //转换
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    //启用/禁用
    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingLevelMapper.enableOrDisable(id, status);
    }

    //删除
    @Override
    public void removeNursingLevel(Long id) {
        nursingLevelMapper.removeNursingLevel(id);
    }

    //根据id查询护理等级
    @Override
    public NursingLevelVO selectById(Long id) {
        //转换
        NursingLevel nursingLevel = nursingLevelMapper.selectById(id);
        return BeanUtil.copyProperties(nursingLevel, NursingLevelVO.class);
    }

    //查询所有护理等级
    @Override
    public List<NursingLevelVO> selectAll() {
        //封装集合
        List<NursingLevel> nursingLevels = nursingLevelMapper.selectAll();
        //转换
        return BeanUtil.copyToList(nursingLevels, NursingLevelVO.class);
    }

    // 分页查询
    @Override
    public PageResponse<NursingLevelVO> selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        // 拿到name和status
        Page<NursingLevel> nursingLevels = nursingLevelMapper.selectByPage(name, status);
        //转换成vo
        PageResponse<NursingLevelVO> nursingLevelVoPageResponse = PageResponse.of(nursingLevels, NursingLevelVO.class);
        return nursingLevelVoPageResponse;
    }
}
